﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Text_Adventures
{
    public class Room
    {

        public string Name { get; set; }
        public string North { get; set; }
        public string South { get; set; }
        public string West { get; set; }
        public string East { get; set; }
        public string Description { get; set; }
        public List<Character> Npcs { get; set; }
        public List<Item> Items { get; set; }

        public Room(StreamReader sr)
        {
            Npcs = new List<Character>();
            Items = new List<Item>();
            int blankCount = 0;
            string line = "";

            while (!line.Equals("end") && blankCount < 2 && !sr.EndOfStream)
            {
                if (!sr.EndOfStream && ((line = sr.ReadLine().ToLower().Trim()) != ""))
                {
                    switch (line)
                    {
                        case "name":
                            line = sr.ReadLine();
                            Name = line;
                            blankCount = 0;
                            break;
                        case "north":
                            line = sr.ReadLine();
                            North = line;
                            blankCount = 0;
                            break;
                        case "south":
                            line = sr.ReadLine();
                            South = line;
                            blankCount = 0;
                            break;
                        case "east":
                            line = sr.ReadLine();
                            East = line;
                            blankCount = 0;
                            break;
                        case "west":
                            line = sr.ReadLine();
                            West = line;
                            blankCount = 0;
                            break;
                        case "description":
                            line = sr.ReadLine();
                            Description = line;
                            blankCount = 0;
                            break;
                        case "npcs":
                            line = sr.ReadLine();
                            string[] npcs = line.Split(',');                            
                            for (int i = 0; i < npcs.Length ; i++)
                            {
                                StreamReader reader = new StreamReader(@"Data\Chars.txt");
                                Character Char = new Character(reader,npcs[i]);
                                Npcs.Add(Char);
                                reader.Close();
                            }
                            blankCount = 0;
                            break;
                        case "items":
                            line = sr.ReadLine();
                            string[] items = line.Split(',');
                            for (int i = 0; i < items.Length; i++)
                            {
                                StreamReader reader = new StreamReader(@"Data\Items.txt");
                                Item item = new Item(reader, items[i]);
                                Items.Add(item);
                                reader.Close();
                            }
                            blankCount = 0;
                            break;
                        case "":
                            blankCount++;
                            break;
                        default:
                            break;
                    }                    
                }
            }
        }
    
    
    
    
    }
}
